#include <iostream>
#include <vector>
using namespace std;
 
 int main()
 {
         string str;
             cin >> str;
                 int res = 1e9;
                     for(char ch = 'a'; ch <= 'z'; ++ch)
                         {
                                     int cnt = 0;
                                             for(auto e : str)
                                                     {
                                                                     cnt += min(abs(e - ch), 26 - abs(e - ch));
                                                     }
                                                             res = min(res, cnt);
                         }
                             cout << res << endl;
                                 return 0;
 }
                                                     }
                         }
 }